import Mock from "mockjs"
Mock.setup({
    timeout:"200-600" //设置延迟时间
})



//echart图表接口 折线图
Mock.mock("http://127.0.0.1:8081/chartData","get",()=>{
  return {
    code:200,
    message:"操作成功",
    data:{
      list:[
        {name:"订单11",data:[20, 50, 30, 70, 60, 80, 40, 60, 50]},
        {name:"订单22",data:[40, 60, 50, 80, 70, 90, 60, 70, 80]},
        {name:"订单33",data:[30, 40, 60, 50, 70, 20, 30, 40, 60]}
      ]
    }
  }
})

////echarts图表数据接口2 饼图
Mock.mock("http://app-admin-test.wadichat.com/chartData2",'get',()=>{
  return {
    code: 200,
    message: '操作成功',
    data: {
      list:[
        { value: 35, name: '订单1' },  // 数据值和名称
        { value: 30, name: '订单2' },
        { value: 25, name: '订单3' }
      ]
    }
  };
})
//echarts图表数据接口3 雷达图
Mock.mock("http://app-admin-test.wadichat.com/chartData3",'get',()=>{
  return {
    code: 200,
    message: '操作成功',
    data: {
      list: [42, 30, 200, 350, 500, 180]
    }
  };
})



//营收统计图表
Mock.mock("http://app-admin-test.wadichat.com/revenueChart", "get", () => {
  return {
    code: 200,
    success: true,
    data: {
      list:[
        {
          name:"销售",
          data:[60, 40, 120, 140, 160, 80, 140]
        },
        {
          name:"访问量",
          data:[600, 400, 600, 700, 800, 400, 700]
        },

      ]
    }
  };
})




//订单管理接口
Mock.mock('http://app-admin-test.wadichat.com/orderList', 'post', (options: any) => {
  const { pageSize } = JSON.parse(options.body);
  console.log("后端订单管理接到参数", JSON.parse(options.body))
  return {
    code: 200,
    message: "成功",
    data: Mock.mock({
      [`list|${pageSize}`]: [{
        'orderNo': '@string("number", 6)', //订单号
        'date': '@date("yyyy-MM-dd")',//订单日期
        'startTime': "08:00:23",//开始时间
        'endTime': "09:10:11",//结束时间
        "equipmentNo|1": ['B109', 'C227', 'C106', "D158"],//设备编号
        'money|1': [66.5,88.9,22.7,36.5,42.0],//金额
        'pay|1': ["微信", "支付宝", "储值卡",],//支付方式
        'status|1': [2, 3, 4],//订单状态
      }],
      "total": 54
    })
    // 生成55条数据
  }
});


//订单管理-批量删除接口
Mock.mock('http://app-admin-test.wadichat.com/batchDelete', "post", (options: any) => {
  const { order } = JSON.parse(options.body)
  console.log("订单管理批量删除接口",JSON.stringify(order) )
  return {
    code: 200,
    message: "成功",
    data: "操作成功"
  }
})


//计费管理城市接口
Mock.mock('http://app-admin-test.wadichat.com/cityList', "get", () => {
  return {
    code: 200,
    message: "操作成功",
    data: []
  }
})




Mock.mock('http://app-admin-test.wadichat.com/alarmList', "get", () => {
  return {
    code: 200,
    message: "操作成功",
    data: []
  }
})

//会员卡管理接口
Mock.mock('http://app-admin-test.wadichat.com/member', 'post', (req:any) => {
  const { page, pageSize,no,tel,name } = JSON.parse(req.body);
  console.log("会员管理接口",page, pageSize,no,tel,name)
  return {
    "code": 200,
    "message": "操作成功",
    data: Mock.mock({
      [`list|${pageSize}`]:[{
        'memberCardNumber': '@id',  // 会员卡号
        'cardType|1': ["普通卡", "VIP卡", "季卡"],  // 卡类型
        'issueDate': '@date("yyyy-MM-dd")',  // 开卡日期
        'holderName': '@cname',  // 持有人姓名
        'holderPhone': /^1[3-9]\d{9}$/,  // 持有人电话
        'cardBalance': '@float(100, 10000, 2, 2)',  // 卡余额
        'transactionRecords|1-5': [{  // 消费记录
            'transactionDate|1': ["2024-02-18","2024-04-08","2024-10-03","2024-10-15"],  // 消费日期
            'transactionAmount': '@float(10, 500, 2, 2)',  // 消费金额
            'transactionType|1': ["充电扣款", "服务费扣款", "停车费扣款", "其他"]  // 消费类型
        }],
        'validUntil': '@date("yyyy-MM-dd")'  // 有效期至
    }],
    total:53
    })
  }
});


//招商管理分类列表接口
Mock.mock('http://app-admin-test.wadichat.com/document',"get",()=>{
  return {
    code:200,
    message:"操作成功",
    data:{
      type:["招商类","广告类","公告类","提示类","日常类","告警类","其他"],//文章类型
      important:["一级","二级","三级","四级"],//重要程度
      publish:["站内信","公众号","小程序","H5","官网"]//发布渠道
    }
  }
})

// 自定义生成随机账号函数
Mock.Random.extend({
  account: function() {
    const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    const length = Mock.mock('@natural(6, 10)');
    let result = '';
    for (let i = 0; i < length; i++) {
      result += chars.charAt(Math.floor(Math.random() * chars.length));
    }
    return result;
  }
})
//权限设置页面
Mock.mock('http://app-admin-test.wadichat.com/permissionList','post',(req:any)=>{
  const {pageSize} = JSON.parse(req.body);
  console.log("权限设置接口收到参数",JSON.parse(req.body)) 
return {
    code:200,
    message:"操作成功",
    data:Mock.mock({
      [`list|${pageSize}`]:[{
        'name': '@cname',  // 姓名
        'account': '@account',//账号
        'phone': /^1[3-9]\d{9}$/,  // 电话
        'idNo': '@id',  // 身份证号
        'position|1':["客服专员",'客服经理','市场专员',"市场经理","运营专员","运营经理","技术工程师","技术经理","Boss"],//职位
        'department|1':['总裁办','技术部','市场部','维修部','运营部','客服部'],//所属部门
        "pageAuthority|1":['admin','manager','user','自定义权限'],//页面权限
        'btnAuthority|1':['add','delete','edit','all','自定义权限'],//按钮权限
    }],
    total:41
    })
  }
})


//获取当前用户权限
Mock.mock("http://app-admin-test.wadichat.com/userAuth","post",(req:any)=>{
 //console.log(234,req.body)
 const {pageAuthority}=JSON.parse(req.body)
  console.log("后端收到当前权限",pageAuthority)
  return {
    code:200,
    message:"操作成功",
    data:{
      list:pageAuthority=="user"? []:(pageAuthority=="manager"?[]:[]),
      btn:pageAuthority=="user"?['add']:(pageAuthority=="manager"?['add',"edit"]:['add',"edit","all","delete"])
    }
  }
})

//权限设置接口
Mock.mock("http://app-admin-test.wadichat.com/setAuth","post",(req:any)=>{
  const {btnList,pageList,account}=JSON.parse(req.body)
  console.log("权限设置接口修改账号权限",account,btnList,pageList)
  return{
    code:200,
    message:"操作成功",
    data:null
  }
})

